﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.VideoSurveillance;
namespace Plate
{
    public partial class VideoRecognitionForm : Form
    {
        string VideoFilename;
        public VideoRecognitionForm(string filename)
        {
            this.VideoFilename = filename;
            InitializeComponent();
        }
        Capture Capture;
        private void VideoRecognitionForm_Load(object sender, EventArgs e)
        {
            this.Capture = new Capture(this.VideoFilename);
            Application.Idle += new EventHandler(Application_Idle);
        }

        void Application_Idle(object sender, EventArgs e)
        {
            if(this.Capture==null)
                return;
            Image<Bgr, byte> frame = this.Capture.QueryFrame();
            if (frame == null)
                return;
            Bitmap bmp = frame.ToBitmap();
            SignDetection.SignDetector detector = SignDetection.SignDetector.CreateSignDetector();
            SignDetection.PlatePositionResult result = detector.PlatePositioning(bmp);
            Graphics g = Graphics.FromImage(bmp);
            g.DrawRectangle(new Pen(Color.Red), result.Position);
            this.pictureBox1.Image = bmp;
        }
    }
}
